<?php
    //header ("Location: ".find_in_path('logs/sales_sources.txt'));
    header("Content-Type: text/csv; charset=utf-8");
    
    header('Content-disposition: attachment; filename=' . basename(find_in_path('alohacart_logs/orders.csv')));
    $orders = sql_fetch_all(sql_select('*','spip_alohacart_orders'));
    // Выводим заголовок:
    $i = 1;
    //$head = $orders[0]; 
    foreach ($orders[0] as $key=>$value){
        echo $key;
        if ($i!=count($orders[0]))
                echo ',';
        $i++;
    }
    echo "\n";
    // Выводим заказы:
    foreach ($orders as $order) {
        $i = 1;
        foreach ($order as $key=>$value) {
            if ($key=='id_order') continue;
            echo $value;
            if ($i!=count($order)-1)
                echo ',';
            $i++;
        } 
        echo "\n";
    }
    //echo file_get_contents(find_in_path('alohacart_logs/orders.csv'));
    exit;
?>